package com.google.code.avajhelpdesk.pages;


import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;

import com.google.code.avajhelpdesk.MyWebSession;
import com.google.code.avajhelpdesk.entities.User;
import com.google.code.avajhelpdesk.pages.panels.NotSignedUserInfoPanel;
import com.google.code.avajhelpdesk.pages.panels.SignedUserInfoPanel;
import com.google.code.avajhelpdesk.pages.panels.sidebar.BasicSidebarPanel;


public abstract class BasePage extends WebPage {

	public BasePage() {
		add(new Label("base-page-title", getPageTitle()));
		add(getPanelBeforeContent("panel-before-content"));
		add(getPanelAfterContent("panel-after-content"));
		add(getUserInfoPanel("user-info-panel"));
		add(getSidebarPanel("sidebar"));
		
		add(new BookmarkablePageLink<HomePage>("company-logo-link", HomePage.class));
	}

	private Panel getSidebarPanel(String markupId) {
		return new BasicSidebarPanel(markupId);
	}

	protected Panel getUserInfoPanel(String markupId) {
		if (getCurrentSession().isSignedIn()) {
			return new SignedUserInfoPanel(markupId);
		} else {
			return new NotSignedUserInfoPanel(markupId);
		}
	}
	
	protected Panel getPanelAfterContent(String markupId) {
		return new EmptyPanel(markupId);
	}

	protected Panel getPanelBeforeContent(String markupId) {
		return new EmptyPanel(markupId);
	}

	protected abstract String getPageTitle();	
	
	protected User getCurrentUser() {
		return getCurrentSession().getUser();
	}
	
	protected MyWebSession getCurrentSession() {
		return (MyWebSession) getSession();
	}
}
